import type { AxiosOperator } from '@/common/infrastructure/axios_operator.ts'
import type { AuthorityInfo } from '@/common/model/app_server/outputs/authority_info'
import type { PageModel } from '@/common/model/app/page_model'

export class AuthorityApi {
  // 请求操作者
  private _requestOperator: AxiosOperator

  // 权限请求路由
  private controller: string = '/Authorization'

  /**
   * 有参构造方法
   * @param requestOperator 请求操作者
   * */
  constructor(requestOperator: AxiosOperator) {
    this._requestOperator = requestOperator
  }

  //region # 创建权限 —— createAuthority(adminRoleId: string...)
  /**
   * 创建权限
   * @param adminRoleId 系统管理员Id
   * @param authorityName 权限名称
   * @param authorityPath 权限路径
   * @param description 描述
   * */
  public async createAuthority(adminRoleId: string, authorityName: string, authorityPath: string, description: string) {
    await this._requestOperator.post(`${this.controller}/CreateAuthority`, {
      adminRoleId,
      authorityName,
      authorityPath,
      description,
    })
  }
  //endregion

  //region # 修改权限 —— updateAuthority(authorityId: string...)
  /**
   * 修改权限
   * @param authorityId 权限Id
   * @param authorityName 权限名称
   * @param authorityPath 权限路径
   * @param description 描述
   * */
  public async updateAuthority(authorityId: string, authorityName: string, authorityPath: string, description: string) {
    await this._requestOperator.post(`${this.controller}/UpdateAuthority`, {
      authorityId,
      authorityName,
      authorityPath,
      description,
    })
  }
  //endregion

  //region # 删除权限 —— removeAuthority(authorityId: string)
  /**
   * 删除权限
   * @param authorityId 权限Id
   * */
  public async removeAuthority(authorityId: string) {
    await this._requestOperator.post(`${this.controller}/RemoveAuthority`, {
      authorityId,
    })
  }
  //endregion

  //region # 获取权限 —— etAuthority(authorityId: string...)
  /**
   * 获取权限
   * @param authorityId 权限Id
   * */
  public async getAuthority(authorityId: string): Promise<AuthorityInfo> {
    return await this._requestOperator.get(`${this.controller}/GetAuthority`, {
      authorityId,
    })
  }
  //endregion

  //region # 分页获取权限列表 —— getAuthoritiesByPage(keywords: string...)
  /**
   * 分页获取权限列表
   * @param keywords 关键字
   * @param pageIndex - 页码
   * @param pageSize - 页容量
   * */
  public async getAuthoritiesByPage(keywords: string | null, pageIndex: number, pageSize: number): Promise<PageModel<AuthorityInfo>> {
    return await this._requestOperator.get(`${this.controller}/GetAuthoritiesByPage`, {
      keywords,
      pageIndex,
      pageSize,
    })
  }

  //endregion

}
